/* The Parallel 3D Navier-Stokes Solver*/

#ifndef LIST_INCLUDED
#define LIST_INCLUDED
#include <stdio.h>
#include <iostream>
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif 

// this template class provides an unsorted list with read/write functionality
template <class T>
class NS_List 
{
   protected:
      NS_List* next; // pointer to next element
   public:
      T data; // data type listed
      NS_List()// constructor
      {
         next=0;
         size = 0;
      } 
      int size;
      ~NS_List() // destructor: delete all elements
      {
         NS_List* p=next,*p1;
         while(p) 
         {
            p1=p->next;
            p->next=0;
            delete p;
            p=p1;
         }
         size = 0;
      }
      
      NS_List* GetNext() 
      {
         return next;
      } 
      
      void Delete() // empty the whole list
      {
         NS_List* p=next,*p1;         
         while(p)
         {
            p1=p->next;
            p->next=0;
            delete p;
            p=p1;
         }
         Init();
      }
      
      void    Init() 
      {
         next=0;
         size = 0;
      } 
      
      void    InsertFirst(NS_List* p) // insert element at first position
      {
         p->next=next;
         next=p;
         size++;
      }
      void remove(int indice)
      {         
         std::cout << "\n Entrei no remove";
         int i = 1;
         //next = primeiro elemento da lista
         NS_List *p_aux,*p1;
         p_aux = next;
         std::cout << "\n p->data = " << p_aux->data;
         std::cout << "\n p_aux->next->data = " << (p_aux->next)->data;
         //std::cout << "\n p_aux->next->data = " << (p_aux->next)->data;
         if((indice == 1)  && (p_aux != NULL))
         {
             std::cout << "\n Entrei no if indice ==1";
            p1 = p_aux;            
            p_aux = p_aux->next;
            next = p_aux;
            std::cout << "\n Entrei no delete";
            delete p1;
            std::cout << "\n Voltei do delete";            
            size--;
         }
         else
         {
            while((p_aux) && i < indice-1 )
            {  
               p_aux = p_aux->next;
               i++;
            }
            p1 = p_aux->next;
            p_aux->next = (p_aux->next)->next;
            delete p1;
            size--;
         }
      }
};
#endif












